package com.wlhse.service.impl;

import com.wlhse.dao.ChangQinCompanyDao;
import com.wlhse.dao.CompanyDao;
import com.wlhse.entity.CompanyPojo;
import com.wlhse.service.ChangQinCompanyService;
import com.wlhse.util.R;
import com.wlhse.util.TreeUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;


@Service
public class ChangQinCompanyServiceImpl implements ChangQinCompanyService {

    @Resource
    private ChangQinCompanyDao changQinCompanyDao;

    @Resource
    private TreeUtil treeUtil;

    @Override
    public R listTreeCompany() {
        R ok = R.ok();
        ok.put("data", treeUtil.getChangQinCompanyTree(changQinCompanyDao.queryCompany()));
        return ok;
    }

    @Override
    public R listCurrentTreeCompany(Integer id) {
        //当前登陆人id对应code
        String code = changQinCompanyDao.getCompany(id);
        CompanyPojo company = changQinCompanyDao.getCompanyByCode(code);
        //能找到cate1的按cate1，不能就按当前登陆人对应code
        if (company!=null&&company.getCategory1()!=null){
            code = company.getCategory1();
        }
        System.out.println(code);
        R ok = R.ok();
        ok.put("data", treeUtil.getCompanyTree(changQinCompanyDao.queryCurrentCompany(code)));
        return ok;
    }

}

